<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * API 接口使用
 * Created by PhpStorm.
 * User: 66diqiu-li
 * Date: 14-8-1
 * Time: 上午9:18
 */
class Order_Api_module extends CI_Module{

    /**
     * 构造函数
     */
    function __construct(){
        parent::__construct();
        $this->load->model('order.Orderlog_model');
        $this->load->model('order.Orderpaylog_model');
        $this->load->model('order.Ordertourist_model');
        $this->load->model('order.Ordercontacts_model');
        $this->load->model('order.Ordergodateprice_model');
        $this->load->model('order.Ordergodate_model');
        $this->load->model('order.Orderinfo_model');
        $this->load->model('order.Orderticket_model');
       
       
        
    }

    /**
     * API 线路订单
     */
    public function sales_index(){
        $admin_user_id = (int)$this->input->get_post('id',TRUE);
        $perpage  = $this->input->get_post('pagesize')?(int)$this->input->get_post('pagesize'):10;
        $nowindex = $this->input->get_post('page')?(int)$this->input->get_post('page'):1;
        $result = array();
        $data = array();
        if($admin_user_id!=0){
            $where = array('admin_user_id'=>$admin_user_id,'order_type'=>1);
        $result = $this->Orderinfo_model->get_list($perpage,$nowindex,$where);
            $total = $this->Orderinfo_model->get_count($where);
        }
        if(!empty($result)){
            $data['info'] = $result;
            $data['error_code'] = 0;
        }else{
            $data['message'] = '没有数据信息';
            $data['error_code'] = 1;
        }
        $this->ajaxReturn($data);
    }

    /**
     * API线路详细订单
     */
    public function sales_info(){
        $order_id = $this->input->get('order_id')?$this->input->get('order_id'):0;//订单ID
        $admin_user_id = $this->input->get('admin_id')?$this->input->get('admin_id'):0;//管理员ID

        //订单基本信息
        $order_row = $this->Orderinfo_model->get_row(array('order_id'=>$order_id,'admin_user_id'=>$admin_user_id));
        $return_data = array();
        //判断订单信息是否存在
        if(!empty($order_row)){

            //联系人信息
            $contact_row = $this->Ordercontacts_model->get_row(array('order_id'=>$order_id));

            //游客列表信息
            $tourist_row = $this->Ordertourist_model->get_list(array('order_id'=>$order_id));

            //订单团期基本信息
            $go_date = $this->Ordergodate_model->get_row(array('order_id'=>$order_id));

            //团期价格体系信息 已选择的
            $price_cate = $this->Ordergodateprice_model->get_list(array('order_id'=>$order_id));

            $data['contact_info'] = $contact_row;
            $data['tourist_info'] = $tourist_row;
            $data['order_info'] = $order_row;
            $data['go_date_info'] = $go_date;
            $data['price_list'] = $price_cate;
            $return_data['error_code'] = 0;
            $return_data['info'] = $data;
        }else{
            $return_data['error_code'] = 1;
            $return_data['message'] = '该订单不存在!';
        }
        return $this->ajaxReturn($return_data);
    }

    /**
     * API门票订单列表
     */
    public function ticket_index(){
        $admin_user_id = (int)$this->input->get_post('id',TRUE);
        $perpage  = $this->input->get_post('pagesize')?(int)$this->input->get_post('pagesize'):10;
        $nowindex = $this->input->get_post('page')?(int)$this->input->get_post('page'):1;
        $result = array();
        $data = array();
        if($admin_user_id!=0){
            $where = array('admin_user_id'=>$admin_user_id,'order_type'=>2);
            $result = $this->Orderinfo_model->get_index_ticket_list($perpage,$nowindex,$where);
            $total = $this->Orderinfo_model->get_ticket_count($where);
        }
        if(!empty($result)){
            $data['info'] = $result;
            $data['error_code'] = 0;
        }else{
            $data['message'] = '没有数据信息';
            $data['error_code'] = 1;
        }
        $this->ajaxReturn($data);
    }

    /**
     * API门票订单详情
     */
    public function ticket_info(){
        $order_id = $this->input->get('order_id')?$this->input->get('order_id'):0;//订单ID
        $admin_user_id = $this->input->get('admin_id')?$this->input->get('admin_id'):0;//管理员ID

        //订单基本信息
        $order_row = $this->Orderinfo_model->get_row(array('order_id'=>$order_id,'admin_user_id'=>$admin_user_id));
        $return_data = array();
        //判断订单信息是否存在
        if(!empty($order_row)){

            //联系人信息
            $contact_row = $this->Ordercontacts_model->get_row(array('order_id'=>$order_id));

            //门票信息
            $table = $this->db->dbprefix("order_tickets");
            $ticket_info = $this->Orderticket_model->get_row(array($table.'.order_id'=>$order_id));

            $data = array(
                'contact_info' => $contact_row,
                'order_info' => $order_row,
                'ticket_info' => $ticket_info,
                'category' => array(
                    1 => '成人票',
                    2 => '儿童票',
                    3 => '老年票',
                    4 => '家庭票',
                    5 => '亲子票',
                    6 => '特惠票',
                ),
                'basic_type' => array('套票','单票'),
            );

            $return_data['error_code'] = 0;
            $return_data['info'] = $data;
        }else{
            $return_data['error_code'] = 1;
            $return_data['message'] = '该订单不存在!';
        }
        return $this->ajaxReturn($return_data);
    }
}